package cn.strive.eams.roomHave.service.impl;

import cn.strive.eams.roomHave.mapper.RoomHaveMapper;
import cn.strive.eams.roomHave.pojo.dto.RoomHaveQuery;
import cn.strive.eams.roomHave.pojo.dto.RoomHaveSaveParam;
import cn.strive.eams.roomHave.pojo.entity.RoomHave;
import cn.strive.eams.roomHave.pojo.vo.RoomHaveVO;
import cn.strive.eams.roomHave.service.RoomHaveService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class RoomHaveServiceImpl implements RoomHaveService {
    @Autowired
    RoomHaveMapper roomHaveMapper;
    @Override
    public List<RoomHaveVO> selectAll(RoomHaveQuery roomHaveQuery) {
        log.debug("查询房间资产业务,参数:{}",roomHaveQuery );
        return roomHaveMapper.selectAll(roomHaveQuery);
    }

    @Override
    public void save(RoomHaveSaveParam roomHaveSaveParam) {
        log.debug("保存房间资产,参数：{}",roomHaveSaveParam);
        List<Long> assetIds = roomHaveSaveParam.getAssetId();
        for (Long assetId : assetIds){
            RoomHave roomHave = new RoomHave();
            roomHave.setAssetId(assetId);
            roomHave.setRoomId(roomHaveSaveParam.getRoomId());
            roomHaveMapper.insert(roomHave);
        }
    }

    @Override
    public void deleteById(Long id) {
        log.debug("删除教室里面的资产:id={}",id);
        roomHaveMapper.deleteById(id);
    }
}
